from pycparser import c_ast, c_generator
import sys
sys.path.extend(['.', '..'])
from c_ast_decl import ASTBuilder

builder = ASTBuilder()

a = c_ast.ID(name='a')
b = c_ast.ID(name='b')

cond_outer = c_ast.BinaryOp(op='>', left=a, right=c_ast.Constant(type='int', value='0'))
cond_inner = c_ast.BinaryOp(op='<', left=b, right=c_ast.Constant(type='int', value='5'))

with builder.if_then(cond_outer):
    with builder.if_then(cond_inner):
        stmt1 = c_ast.Assignment(op='=', lvalue=a, rvalue=c_ast.Constant(type='int', value='1'))
        builder.add_statement(stmt1)
    with builder.if_else():
        stmt2 = c_ast.Assignment(op='=', lvalue=b, rvalue=c_ast.Constant(type='int', value='2'))
        builder.add_statement(stmt2)
with builder.if_else():
    stmt3 = c_ast.Assignment(op='=', lvalue=a, rvalue=c_ast.Constant(type='int', value='0'))
    builder.add_statement(stmt3)

generator = c_generator.CGenerator()
print(generator.visit(builder.root))